﻿<%@ WebHandler Language="C#" Class="LoadMapHandler" %>

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Business.Common;
using Business.FlowOperation;
using Business.Map;
using WF_Business;

public class LoadMapHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var flag = context.Request["flag"];
        context.Response.ContentType = "text/plain";
        context.Response.Write(GetJsonStr(flag));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    private string GetJsonStr(string flag)
    {
        var dtMarkInfo = MapBLL.GetMarkInfo(flag);
        var overlayList = new List<MapOverlay>();
        dtMarkInfo.Rows.Cast<DataRow>().ToList().ForEach(row =>
        {
            var bdcId = row["bdcid"].ToString();
            var dtMarkLocation = MapBLL.GetMarkLocation(bdcId);
            var pointList = new List<MapPoint>();
            dtMarkLocation.Rows.Cast<DataRow>().ToList().ForEach(point => pointList.Add(new MapPoint { X = point["x"].ToString(), Y = point["y"].ToString() }));
            var model = new MapOverlay
            {
                BdcId = bdcId,
                BdcName = row["bdcname"].ToString(),
                XmIID = row["xmiid"].ToString(),
                Markattr = row["markattr"].ToString(),
                DataType = row["datatype"].ToString(),
                Purpose = row["purpose"].ToString(),
                FormId = MapBLL.GetFormId(row["datatype"].ToString()),
                PointList = pointList
            };
            overlayList.Add(model);
        });
        var result = new MapMarkInfo { OverlayList = overlayList };
        return result.T2Json();
    }
}